package com.li.onjava8.concurrent.under.exception;

import com.li.onjava8.concurrent.under.exception.ExceptionThread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 即使在 main() 方法体内包裹 try-catch 代码块来捕获异常也不成功：
 */
public class NaiveExceptionHandling {

    public static void main(String[] args) {
        ExecutorService exec = Executors.newCachedThreadPool();
        try {
            exec.execute(new ExceptionThread());
        } catch (Exception e) {
            //捕获不到异常
            System.out.println("Exception was handled!");
        } finally {
            exec.shutdown();
        }
    }

}
